/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var subnavEvents = require("../handler/subnavEvents");
	var user = require("store").get("user");
	
    var instance = {
        initComponent: function (params, widget) {
        	var subnav = new Subnav({
            	parentNode:".J-subnav",
				model : {
					title:"退房查房",
					items : [{
					      id :"servicePoint",
					      type : "buttongroup",
					      tip : "服务点",
					      keyField :"pkServicePoint",
					      valueField : "name",
					      items:user.privateServicePoints,
//					      lazy:true,
//					      url : "api/servicepoint/operableservicepoints",
					      params : function(){
					    	  return{
					    		  fetchProperties:"pkServicePoint,name"
					    	  }
					      },
					      handler : function(key,element){
					    	  subnavEvents.loadBuilding(widget);
					      }
				    },{
						id: "buildings",
						type: "buttongroup",
						tip: "楼宇",
						all: {
			                show: true,
			                position: "top",
			                text: "全部"
			            },
						url : "api/orgbuilding/query",
						keyField: "pkOrgBuilding",
						valueField: "name",
						lazy : true,
						handler: function(key,element){
							widget.get("grid").refresh();
						}
				    },{
						id : "checkOutStatus",
						tip:"退房状态",
						type:"buttongroup",
						all: {
			                show: true,
			                position: "top",
			                text: "全部"
			             },
						items:[{
							key:"NoCheckOut",
							value:"未查房"
						},{
							key:"CheckOut",
							value:"已查房"
						}],
						handler:function(key,element){
							widget.get("grid").refresh();
						}
					},{
						id : "travelDate",
						type:"daterange",
						ranges : {
							"本年": [moment().startOf("year"), moment().endOf("days")],
			                "本日": [moment().startOf("days"), moment().endOf("days")],
			                "本月": [moment().startOf("month"), moment().endOf("month")]
						},
						tip:"日期",
						defaultRange: "本日",
						handler : function(time){
							 widget.get("grid").refresh();
						}
					},{
						id : "save",
						type : "button",
						text : "保存",
						show : false,
						handler : function(){
							subnavEvents.consumpData(widget);
						}
					},{
						id : "cancel",
						type : "button",
						text : "返回",
						show : false,
						handler : function(){
							widget.hide([".J-form",".J-topform", ".J-editgrid"]).show(".J-grid");
							widget.get("subnav").hide(["save", "cancel"]).show(["servicePoint", "checkOutStatus", "travelDate","buildings"]);
							widget.get("form").reset();
							widget.get("topform").reset();
						}
					},{
						id : "return",
						type : "button",
						text : "返回",
						show : false,
						handler : function(){
							widget.hide([".J-consumpeditgrid",".J-consumpdetailgrid"]).show([".J-form",".J-topform", ".J-editgrid"]);
							widget.get("subnav").hide(["save", "return"]).show(["cancel"]);
							widget.get("subnav").setTitle("退房查房");
						}
					}]
				}
            });
            widget.set("subnav", subnav);
        }
    };
    module.exports = instance;
});
